package ae.pcfc.etks.cld.to.web.constraints;



import java.util.Date;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.joda.time.DateTime;
import org.joda.time.Months;

import ae.pcfc.etks.cld.service.common.ConstantsCommon;

/**
 * 
 * @author ammar
 *
 */

public class PassportExpiryValidator implements ConstraintValidator<PassportExpiry, Date> {
	
	public void initialize(PassportExpiry expiryDate) {
	}
 
	public boolean isValid(Date passportExpiry, ConstraintValidatorContext ctx) {
		if (passportExpiry == null)
			return false;
 
		Months months = Months.monthsBetween(new DateTime(), new DateTime(passportExpiry));
		
		if (months.getMonths() < ConstantsCommon.__PASSPORT_EXPIRY_VALID_MONTHS)
			return false;
		
		return true;
	}
}

 
